<?php
/**
 * Notes:
 * User: wudg <544038230@qq.com>
 * Date: 2025/10/17 15:41
 */

namespace App\Controller\User;


use App\Controller\ApiController;
use App\Request\User\MemberListRequest;
use App\Request\User\UserMemberCardSaveRequest;
use App\Request\User\UserMemberCardUseHandleRequest;
use App\Service\User\UserMemberService;
use Hyperf\Di\Annotation\Inject;

class MemberController extends ApiController
{

    #[Inject]
    protected UserMemberService $userMemberService;

    public function index(MemberListRequest $request)
    {
        $params = $request->all();

        list($total,$memberData) = $this->userMemberService->getMemberList($params);
        return $this->responseOk([
            'data'=>$memberData,
            'total'=>$total
        ]);

    }




    /**
     * 会员卡划卡消费
     * @param UserMemberCardUseHandleRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function saveMemberCardUseHandle(UserMemberCardUseHandleRequest $request)
    {
        $params = $request->validated();

        $amountInfo = $this->userMemberService->activeWriteOff($params);
        return $this->responseOk($amountInfo);
    }


    /**
     * 会员卡保存
     * @param UserMemberCardSaveRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function saveMemberCard(UserMemberCardSaveRequest $request)
    {
        $params = $request->validated();

        $memberInfo = $this->userMemberService->saveMemberUseHandle($params);

        return $this->responseOk($memberInfo);

    }
}